home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / wtj007.zip / BLOOM.ZIP / PAINTGR.C < prev    next >
Text File  |  1992-07-24  |  3KB  |  103 lines

  1. // sample function
  2.  
  3. void PaintGraphDlgCtrl(HWND hCtrl, short dataOffset)
  4.   {
  5.   HDC    hDC;    /* to create child window's DC */
  6.   RECT   rect;   /* to get child window's
  7.                                      client rect */
  8.   WORD   ctrlID; /* child window's ID in RC file */
  9.   TEXTMETRIC tm;
  10.   HFONT hFontHeading;
  11.   static int xmax,ymax,xoffset,yoffset,i,z;
  12.   static int y=0;
  13.   char buf[20] = "xxx";
  14.   int q,r;
  15.  
  16. /* Find control dimensions */
  17.   ctrlID = GetWindowWord(hCtrl, GWW_ID);
  18.   GetClientRect(hCtrl, &rect);
  19.   InvalidateRect(hCtrl, &rect, TRUE);
  20.   UpdateWindow(hCtrl);
  21.   hDC = GetDC(hCtrl);
  22.  
  23.   xmax = (rect.right - rect.left)*8/10;
  24.   ymax = (rect.bottom - rect.top)*9/10;
  25.   xoffset = rect.left +(rect.right - rect.left)*1/10;
  26.   yoffset = rect.top + (rect.bottom - rect.top)*1/20;
  27.  
  28. /* Draw the coordinates */
  29.  
  30.   MoveTo (hDC,xoffset,yoffset);
  31.   LineTo (hDC,xoffset, yoffset+ymax);
  32.   LineTo (hDC,xoffset+xmax, yoffset+ymax);
  33.  
  34.   yoffset = yoffset + ymax;
  35.   for (i=1;i<5;i++)
  36.     {
  37.     MoveTo(hDC,xoffset+(i*xmax/4),yoffset);
  38.     LineTo(hDC,xoffset+(i*xmax/4),yoffset+3);
  39.     }
  40.   SetBkMode(hDC,TRANSPARENT);
  41.  
  42. /* Put in the coordinate values */
  43.  
  44.   GetTextMetrics(hDC,&tm);
  45.  
  46. /* If the width of the area between the left border
  47.    and the left edge of the control is very small
  48.    change the font to fit into the area.           */
  49.  
  50.   if((tm.tmAveCharWidth*3) >(rect.right - rect.left)
  51.                                                  /10)
  52.     {
  53.     r = ((rect.right - rect.left)/30)+2;
  54.     hFontHeading = CreateFont(8, r,0,0, 300,FALSE,
  55.        FALSE,FALSE,OEM_CHARSET,OUT_CHARACTER_PRECIS,
  56.        OUT_DEFAULT_PRECIS,PROOF_QUALITY,
  57.        VARIABLE_PITCH|FF_ROMAN,"Times");
  58.     SelectObject(hDC,hFontHeading);
  59.     SetBkMode(hDC, TRANSPARENT);
  60.  
  61.     for (i=1;i<5;i++)
  62.       {
  63.       MoveTo(hDC,xoffset-3,yoffset-(i*ymax/5));
  64.       LineTo(hDC,xoffset,yoffset-(i*ymax/5));
  65.       wsprintf((LPSTR)buf,"%1d",20*i);
  66.       TextOut(hDC,rect.left,yoffset-(ymax*i/5),
  67.                                     (LPSTR)buf,2);
  68.       }
  69.     TextOut(hDC,rect.left,yoffset-ymax,(LPSTR)"100",
  70.                                                   3);
  71.     DeleteObject(hFontHeading);
  72.     }
  73.   else
  74.     {
  75.     for (i=1;i<5;i++)
  76.       {
  77.       SelectObject(hDC,hFontTimes);
  78.       MoveTo(hDC,xoffset-3,yoffset-(i*ymax/5));
  79.       LineTo(hDC,xoffset,yoffset-(i*ymax/5));
  80.       wsprintf((LPSTR)buf,"%1d",20*i);
  81.         TextOut(hDC,xoffset-20,yoffset-(ymax*i/5),
  82.                                       (LPSTR)buf,2);
  83.       }
  84.     TextOut(hDC,xoffset-20,yoffset-ymax,
  85.                                     (LPSTR)"100",3);
  86.     }
  87.  
  88. /* Draw the graph */
  89.  
  90.   MoveTo(hDC,xoffset,yoffset);
  91.   for (i=0;i<5;i++)
  92.     {
  93.     y =  statdata[i+dataOffset].itemave * ymax / 100;
  94.     z = (int)y;
  95.     LineTo(hDC,xoffset+(i*xmax/4),yoffset-z);
  96.     Rectangle(hDC,(xoffset+(i*xmax/4))-2,
  97.                 (yoffset-z)-2,(xoffset+
  98.                 (i*xmax/4))+2,(yoffset-z)+2);
  99.     }
  100.   ReleaseDC(hCtrl, hDC);
  101.   }
  102.  
  103.